# -*- coding: utf-8 -*-
from lr.register.models import Profile, AnonymousProfile


class ProfileMiddleware(object):
    """ Препроцессор для профиля пользователя """
    
    def process_request(self, request):
        """ Постобработка запроса """
        if request.user.is_authenticated():
            try:
                profile = Profile.objects.get(user=request.user)
            except:
                profile = None
        else:
            profile = None
        
        if not profile:
            profile = AnonymousProfile()
        request.profile = profile
